package info.wangyuan.agent.utils;

import lombok.extern.slf4j.Slf4j;
import org.apache.tika.Tika;

import java.io.ByteArrayInputStream;
import java.io.IOException;

/**
 * 文件类型检测工具类
 *
 * @author Albert
 * @since 2025-08-16 18:36:03
 */
@Slf4j
public class TikaFileTypeDetector {

    public static String detectFileType(byte[] data) {
        if (data == null || data.length == 0) {
            return "未知类型";
        }

        try {
            return new Tika().detect(new ByteArrayInputStream(data));
        } catch (IOException e) {
            log.error("文件类型检测失败: {}", e.getMessage());
            return "未知类型";
        }
    }

}
